*** Code for The 2016 Election & America's Standing Abroad
*** Regina Bateson and Michael Weintraub
*** Journal of Politics
*** This final version is 8/8/2021 

//Table of Contents//

//1. Prepare the data
//2. Balance Tests for Figure 1
//3. Main results for Figure 2
//4. Changes in predicted probability of trusting US government, by country for Figure 3
//5. Placebo tests for Figures 4 and 5
//6. Tables, results & figures for Appendix A
//7. Tables, results & figures for Appendix B

*****************************************
*****************************************
//1. PREPARE THE DATA//
*****************************************
*****************************************

//Setup: install packages and set scheme for figures
ssc install blindschemes, replace all
ssc install addplot
ssc install texdoc
ssc install ebalance
set scheme plottigblind


//Download data//

//We use the original LAPOP 2016 country files. Due to restrictions imposed by LAPOP, 
//we are unable to post the original LAPOP data files, so users must download them. The datasets are free &
//available from http://datasets.americasbarometer.org/database/login.php

//Users should save the datasets using the following names: "paraguay.dta" "salvador.dta" "dr.dta" "honduras.dta"

//Merge datasets

use "paraguay.dta", clear
append using "salvador.dta"
append using "dr.dta"
append using "honduras.dta"
save "bateson_weintraub.dta",replace


//Label, create, and clean key variables

//Label country variable

label define pais 3 "El Salvador" 4 "Honduras" 12 "Paraguay" 21 "Dominican Republic"
label values pais pais

//Establish TREATMENT variable: 1 = after election; 0 = interviewed on Election Day or before. 
//Note: the US presidential election was held on Nov. 8, 2016 (date=20766), so Nov. 9 (date=20767) is the first day after the election. Dates 20767 and greater are coded post-Trump.
gen posttrump = 0
replace posttrump= 1 if fecha>=20767
label var posttrump "Post-Trump, All Dates"

//Establish varying bandwidths for TREATMENT variable
// The naive version compares ALL post-election interviewees with ALL pre-election interviewees, with no bandwidth restrictions.
gen treatment_naive = . 
replace treatment_naive = posttrump
label var treatment_naive "Post-Trump, All Dates"

* Different bandwidths
//Note: These bandwidths compare respondents contacted within X days after election vs. those contacted within X days before the election.

* 21 Day Bandwidth
gen posttrump_21days=.
replace posttrump_21days = 1 if fecha >=20767 & fecha<=20787
replace posttrump_21days = 0 if fecha< 20767 & fecha>=20746
label var posttrump_21days "Post-Trump 21 Day Window"

* 20 Day Bandwidth
gen posttrump_20days=.
replace posttrump_20days = 1 if fecha >=20767 & fecha<=20786
replace posttrump_20days = 0 if fecha< 20767 & fecha>=20747
label var posttrump_20days "Post-Trump 20 Day Window"

* 19 Day Bandwidth
gen posttrump_19days=.
replace posttrump_19days = 1 if fecha >=20767 & fecha<=20785
replace posttrump_19days = 0 if fecha< 20767 & fecha>=20748
label var posttrump_19days "Post-Trump 19 Day Window"

* 18 Day Bandwidth
gen posttrump_18days=.
replace posttrump_18days = 1 if fecha >=20767 & fecha<=20784
replace posttrump_18days = 0 if fecha< 20767 & fecha>=20749
label var posttrump_18days "Post-Trump 18 Day Window"

* 17 Day Bandwidth
gen posttrump_17days=.
replace posttrump_17days = 1 if fecha >=20767 & fecha<=20783
replace posttrump_17days = 0 if fecha< 20767 & fecha>=20750
label var posttrump_17days "Post-Trump 17 Day Window"

* 16 Day Bandwidth
gen posttrump_16days=.
replace posttrump_16days = 1 if fecha >=20767 & fecha<=20782
replace posttrump_16days = 0 if fecha< 20767 & fecha>=20751
label var posttrump_16days "Post-Trump 16 Day Window"

* 15 Day Bandwidth
gen posttrump_15days=.
replace posttrump_15days = 1 if fecha >=20767 & fecha<=20781
replace posttrump_15days = 0 if fecha< 20767 & fecha>=20752
label var posttrump_15days "Post-Trump 15 Day Window"

* 14 Day Bandwidth
gen posttrump_14days=.
replace posttrump_14days = 1 if fecha >=20767 & fecha<=20780
replace posttrump_14days = 0 if fecha< 20767 & fecha>=20753
label var posttrump_14days "Post-Trump 14 Day Window"

*13 Day Bandwidth
gen posttrump_13days=.
replace posttrump_13days = 1 if fecha >=20767 & fecha<=20779
replace posttrump_13days = 0 if fecha< 20767 & fecha>=20754
label var posttrump_13days "Post-Trump 13 Day Window"

*12 Day Bandwidth
gen posttrump_12days=.
replace posttrump_12days = 1 if fecha >=20767 & fecha<=20778
replace posttrump_12days = 0 if fecha< 20767 & fecha>=20755
label var posttrump_12days "Post-Trump 12 Day Window"

*11 Day Bandwidth
gen posttrump_11days=.
replace posttrump_11days = 1 if fecha >=20767 & fecha<=20777
replace posttrump_11days = 0 if fecha< 20767 & fecha>=20756
label var posttrump_11days "Post-Trump 11 Day Window"

*10 Day Bandwidth
gen posttrump_10days=.
replace posttrump_10days = 1 if fecha >=20767 & fecha<=20776
replace posttrump_10days = 0 if fecha< 20767 & fecha>=20757
label var posttrump_10days "Post-Trump 10 Day Window"

*9 Day Bandwidth
gen posttrump_9days=.
replace posttrump_9days = 1 if fecha >=20767 & fecha<=20775
replace posttrump_9days = 0 if fecha< 20767 & fecha>=20758
label var posttrump_9days "Post-Trump 9 Day Window"

*8 Day Bandwidth
gen posttrump_8days=.
replace posttrump_8days = 1 if fecha >=20767 & fecha<=20774
replace posttrump_8days = 0 if fecha< 20767 & fecha>=20759
label var posttrump_8days "Post-Trump 8 Day Window"

*7 Day Bandwidth
gen posttrump_7days=.
replace posttrump_7days = 1 if fecha >=20767 & fecha<=20773
replace posttrump_7days = 0 if fecha< 20767 & fecha>=20760
label var posttrump_7days "Post-Trump 7 Day Window"

*6 Day Bandwidth
gen posttrump_6days=.
replace posttrump_6days = 1 if fecha >=20767 & fecha<=20772
replace posttrump_6days = 0 if fecha <20767 & fecha >=20761
label var posttrump_6days "Post-Trump 6 Day Window"

*5 Day Bandwidth
gen posttrump_5days=.
replace posttrump_5days = 1 if fecha >=20767 & fecha<=20771
replace posttrump_5days = 0 if fecha< 20767 & fecha>=20762
label var posttrump_5days "Post-Trump 5 Day Window"

*4 Day Bandwidth
gen posttrump_4days=.
replace posttrump_4days = 1 if fecha>=20767 & fecha<=20770
replace posttrump_4days = 0 if fecha< 20767 & fecha>=20763
label var posttrump_4days "Post-Trump 4 Day Window"

*3 Day Bandwidth
gen posttrump_3days=.
replace posttrump_3days = 1 if fecha>=20767 & fecha<=20769
replace posttrump_3days = 0 if fecha< 20767 & fecha>=20764
label var posttrump_3days "Post-Trump 3 Day Window"

*2 Day Bandwidth
gen posttrump_2days=.
replace posttrump_2days = 1 if fecha>=20767 & fecha<=20768
replace posttrump_2days = 0 if fecha< 20767 & fecha>=20765
label var posttrump_2days "Post-Trump 2 Day Window"

//Set up DEPENDENT VARIABLE//

*Recode our main dependent variable, such that larger numbers indicate more trust in the US Government
//Note: in the original LAPOP data, 4=untrustworthy and 1=very trustworthy. We've recoded the variable such that 4=very trustworthy and 1=untrustworthy.
rename mil10e trustusgov
recode trustusgov 1=5
recode trustusgov 4=1
recode trustusgov 5=4
recode trustusgov 2=5
recode trustusgov 3=2
recode trustusgov 5=3

label define trustusgov 1 "Untrustworthy" 2 "Not Very Trustworthy" 3 "Somewhat Trustworthy" 4 "Very Trustworthy"
label values trustusgov trustusgov

*Create dummy variables indicating who responded "Don't Know" re: trust in US gov, and who is coded as "No Response"

gen trustusgovdk=0
replace trustusgovdk=1 if trustusgov==.a
label define trustusgovdk 1 "Doesn't Know if Trusts US Gov" 0 "Did Not Say Doesn't Know if Trusts US Gov"
label values trustusgovdk trustusgovdk

gen trustusgovnr=0
replace trustusgovnr=1 if trustusgov==.b
label define trustusgovnr 1 "No Response to Trust US Gov Question" 0 "Responded to Trust US Gov Question"
label values trustusgovnr trustusgovnr

//Note: Some of our models use a binary version of the dependent variable. 
//This is coded 1 if the respondent says USG is very or somewhat trusthworthy; 0 if they say the USG is not very trustworthy or untrustworthy.

*Create binary dependent variable

gen dummytrustusg=.
replace dummytrustusg=0 if trustusgov==1
replace dummytrustusg=0 if trustusgov==2
replace dummytrustusg=1 if trustusgov==3 
replace dummytrustusg=1 if trustusgov==4
label define dummytrustusg 1 "Trusts US Gov" 0 "Does Not Trust US Gov"
label values dummytrustusg dummytrustusg 

//Rename and recode CONTROL variables//

rename vb2 voted_lastpresidential
recode voted_lastpresidential 2=0
rename vb1 voteregistered
recode voteregistered 2=0
recode voteregistered 3=.
rename ed education
rename ed2 education_mother
rename ocup4a employment
gen working =employment if employment== 1
replace working = 0 if working==.
rename q10new householdincome
rename q1 male
recode male 2=0
rename q2 age
rename q10a remesas
recode remesas 2=0
rename q14 emigrate
recode emigrate 2=0
rename tamano citysize
//Note: In the manuscript, we refer to "citysize" as "Size of Location". It is a 5-point scale: larger numbers are more rural. 1 = Capital metro area and 5 = rural area.

//create citysize dummies for use in some models//
gen capital=0
replace capital=1 if citysize==1
gen largecity=0
replace largecity=1 if citysize==2
gen smallcity=0
replace smallcity=1 if citysize==3
gen town=0
replace town=1 if citysize==4
gen rural=0
replace rural=1 if citysize==5

rename l1 ideology
//Note: lower numbers = more left/liberal; higher numbers = more conservative/right.

rename pais country

//create country dummies//
gen elsalv=0
replace elsalv=1 if country==3
gen honduras=0
replace honduras=1 if country==4
gen dr=0
replace dr=1 if country==21
gen paraguay=0
replace paraguay=1 if country==12 

//Rename and recode additional dependent variables for PLACEBO TESTS: these variables measure trust in other foreign entities

//Trust in CHINESE GOV
//Recode dependent variable so that larger numbers mean more trust in the Chinese government
rename mil10a trustchina
recode trustchina 1=5
recode trustchina 4=1
recode trustchina 5=4
recode trustchina 2=5
recode trustchina 3=2
recode trustchina 5=3

label define trustchina 1 "Untrustworthy" 2 "Not Very Trustworthy" 3 "Somewhat Trustworthy" 4 "Very Trustworthy"
label values trustchina trustchina

gen trustchinadk=0
replace trustchinadk=1 if trustchina==.a
label define trustchinadk 1 "Doesn't Know if Trusts Chinese Gov" 0 "Did Not Say Doesn't Know if Trusts Chinese Gov"
label values trustchinadk trustchinadk

gen trustchinanr=0
replace trustchinanr=1 if trustchina==.b
label define trustchinanr 1 "No Response to Trust Chinese Gov Question" 0 "Responded to Trust Chinese Gov Question"
label values trustchinanr trustchinanr

//Create dummy variable measuring trust in Chinese gov
gen dummytrustchina=.
replace dummytrustchina=0 if trustchina==1
replace dummytrustchina=0 if trustchina==2
replace dummytrustchina=1 if trustchina==3
replace dummytrustchina=1 if trustchina==4

//Note: the trust in Chinese gov question had a high rate of "Don't Know" responses.
//The variables above allow us to analyze the "No response" and "don't know" answers to the question.
//There were 3,765 "Don't Know" answers and 106 answers coded "No Response."

//Trust in UN
//Recode variable so that larger numbers mean more trust in the UN.
rename mil10un trustun
recode trustun 1=5
recode trustun 4=1
recode trustun 5=4
recode trustun 2=5
recode trustun 3=2
recode trustun 5=3

label define trustun 1 "Untrustworthy" 2 "Not Very Trustworthy" 3 "Somewhat Trustworthy" 4 "Very Trustworthy"
label values trustun trustun

gen trustundk=0
replace trustundk=1 if trustun==.a
label define trustundk 1 "Doesn't Know if Trusts UN" 0 "Did Not Say Doesn't Know if Trusts UN"
label values trustundk trustundk

gen trustunnr=0
replace trustunnr=1 if trustun==.b
label define trustunnr 1 "No Response to Trust UN Question" 0 "Responded to Trust UN Question"
label values trustunnr trustunnr

gen dummytrustun=.
replace dummytrustun=0 if trustun==1
replace dummytrustun=0 if trustun==2
replace dummytrustun=1 if trustun==3
replace dummytrustun=1 if trustun==4

//Trust in OAS
//Recode variable so larger numbers mean more trust in the OAS
rename mil10oas trustoas
recode trustoas 1=5
recode trustoas 4=1
recode trustoas 5=4
recode trustoas 2=5
recode trustoas 3=2
recode trustoas 5=3

label define trustoas 1 "Untrustworthy" 2 "Not Very Trustworthy" 3 "Somewhat Trustworthy" 4 "Very Trustworthy"
label values trustoas trustoas

gen trustoasdk=0
replace trustoasdk=1 if trustoas==.a
label define trustoasdk 1 "Doesn't Know if Trusts OAS" 0 "Did Not Say Doesn't Know if Trusts OAS"
label values trustoasdk trustoasdk

gen trustoasnr=0
replace trustoasnr=1 if trustoas==.b
label define trustoasnr 1 "No Response to Trust OAS Question" 0 "Responded to Trust OAS Question"
label values trustoasnr trustoasnr 

gen dummytrustoas=.
replace dummytrustoas=0 if trustoas==1
replace dummytrustoas=0 if trustoas==2
replace dummytrustoas=1 if trustoas==3
replace dummytrustoas=1 if trustoas==4

//CREATE TIME VARIABLE

//Following the recommendations of Munoz et al 2020, we create a time variable, allowing for an interaction term in subsequent analyses
//Nov. 9, 2016 is coded as "zero" for all countries.The variable then counts backward and forward from there.

gen time_zero = fecha-20767
label var time_zero "Days"

//ENTROPY BALANCING

//This section uses ENTROPY BALANCING to ensure similar treatment and control units, using a 7-day window pre & post-election
//We use entropy balancing to preprocess data for our binary treatment, in line with Muñoz et al (2020)

//Install the ebalance package from Hainmueller and Xu (2013). See https://web.stanford.edu/~jhain/Paper/JSS2013.pdf

ssc install ebalance

//Note that the entropy balancing does not consider country or size of location, because these variables are used for fixed effects in our regressions. 

ebalance posttrump_7days male age householdincome education working voted_lastpresidential voteregistered, generate(balance_seven) targets(3)

//Store entropy balancing descriptives into matrix to generate table
matrix pre = e(preBal)
matrix post = e(postBal)

//Generate variable that captures the units included in the entropy balancing weights estimation
gen sample_bal = e(sample)

* Apply generated weights
svyset [pweight=balance_seven]


*************************************
*************************************
//2. BALANCE TESTS FOR FIGURE 1//
*************************************
*************************************

//Create Figure 1: Balance for full sample, 21 day, 14 day, and 7 day bandwidths

clear matrix
foreach var of varlist treatment_naive  posttrump_21days posttrump_14days posttrump_7days  {
	gen r_`var' = `var'
	recode r_`var' (1=0) (0=1)
}

// Conduct t-test and store results in matrix to generate the plot
foreach tr of varlist  treatment_naive  posttrump_21days posttrump_14days posttrump_7days {
	matrix mean = J(1,9,.)
	matrix colnames mean =  male age householdincome citysize education working voted_lastpresidential voteregistered remesas 
	matrix CI = J(4,9,.)
	matrix colnames CI =  male age householdincome citysize education working  voted_lastpresidential voteregistered remesas 
	matrix rownames CI = ll95 ul95 ll90 ul90
	local i 0
	foreach var of varlist  male age householdincome citysize education working  voted_lastpresidential voteregistered remesas {
		quietly: ttest `var', by(`tr') 
		local ++ i 
		local diff =  r(mu_2) - r(mu_1) 
		matrix mean[1, `i'] = `diff' 
		local degrees = r(df_t)
		local critical_5 = invttail(`degrees', 0.025)
		local confvalue_5 = `critical_5' * r(se)
		local critical_10 = invttail(`degrees', 0.05)
		local confvalue_10 = `critical_10' * r(se)
		local ll95 = `diff' - `confvalue_5'
		local ul95 = `diff' + `confvalue_5'
		local ll90 = `diff' - `confvalue_10'
		local ul90 = `diff' + `confvalue_10'
		matrix CI[1, `i'] = `ll95' \ `ul95' \ `ll90' \ `ul90'
	}
matrix `tr'_m = mean
matrix `tr'_CI = CI
}

// Generate figure for balance tests 
label var working "Working"
label var voteregistered "Registered to Vote"
label var voted_lastpresidential "Voted Last Presidential Election"
label var remesas "Remittances"

coefplot (matrix(treatment_naive_m), xline(0) ci((treatment_naive_CI[1] treatment_naive_CI[2]) (treatment_naive_CI[3] treatment_naive_CI[4]))) ///
		|| (matrix(posttrump_21days_m), xline(0, lpattern(solid)) ci((posttrump_21days_CI[1] posttrump_21days_CI[2]) (posttrump_21days_CI[3] posttrump_21days_CI[4]))) ///
		|| (matrix(posttrump_14days_m), xline(0, lpattern(solid)) ci((posttrump_14days_CI[1] posttrump_14days_CI[2]) (posttrump_14days_CI[3] posttrump_14days_CI[4]))) ///
		|| (matrix(posttrump_7days_m), xline(0, lpattern(solid)) ci((posttrump_7days_CI[1] posttrump_7days_CI[2]) (posttrump_7days_CI[3] posttrump_7days_CI[4]))) ///
		, byopts(row(2)) xlabel(-1(.5)1) ylabel(, labsize(small)) xscale(range(-1 1)) xline(0, lpattern(solid))  ///
			nokey nooffset bylabels("Full sample" "± 21 days" "± 14 days" "± 7 days") rescale(male remesas  working voted_lastpresidential voteregistered=15) xtitle("Mean Difference Between Treatment and Control Groups with 90% and 95% Confidence Intervals")
	
	
graph save balancetests_reduced.gph, replace 
graph export balancetests_reduced.png, replace 

drop r_*

*Generate accompanying table, which is Appendix Table B.5. 

//Create balance table for 21 day window

foreach var of varlist male age householdincome citysize education working voted_lastpresidential voteregistered remesas{
	
	reg `var' posttrump_21days
	global m`var'_0: di %6.3fc _b[_cons]
	global m`var'_1: di %6.3fc _b[_cons] + _b[posttrump_21days]
	global dif_`var': di %6.3fc _b[posttrump_21days]

	global lbe_`var' : var label `var'

	qui test posttrump_21days=0
	global p_`var': di %12.3fc r(p)
	glo star_`var'=cond(${p_`var'}<.001,"***",cond(${p_`var'}<.01,"**",cond(${p_`var'}<.05,"*",cond(${p_`var'}<.1,"+",""))))
}

//Output the results of the 21 day window balance test
	texdoc init balance_table_21days.tex, replace force
	tex \begin{tabular}{lccc} \toprule \toprule
	tex Variable			& 	Mean Control	& Mean Treatment & Difference \\
	tex \addlinespace \hline \\
	foreach var of varlist male age householdincome citysize education working voted_lastpresidential voteregistered remesas{
	tex ${lbe_`var'} & ${m`var'_0} & ${m`var'_1} & ${dif_`var'}${star_`var'}\\
	}
	tex \hline \hline
	tex \end{tabular}

	
//Create balance table for 14 day window

foreach var of varlist male age householdincome citysize education working voted_lastpresidential voteregistered remesas{
	
	reg `var' posttrump_14days
	global m`var'_0: di %6.3fc _b[_cons]
	global m`var'_1: di %6.3fc _b[_cons] + _b[posttrump_14days]
	global dif_`var': di %6.3fc _b[posttrump_14days]

	global lbe_`var' : var label `var'

	qui test posttrump_14days=0
	global p_`var': di %12.3fc r(p)
	glo star_`var'=cond(${p_`var'}<.001,"***",cond(${p_`var'}<.01,"**",cond(${p_`var'}<.05,"*",cond(${p_`var'}<.1,"+",""))))
}

//Output the results of the 14 day window balance test
	texdoc init balance_table_14days.tex, replace force
	tex \begin{tabular}{lccc} \toprule \toprule
	tex Variable			& 	Mean Control	& Mean Treatment & Difference \\
	tex \addlinespace \hline \\
	foreach var of varlist male age householdincome citysize education working voted_lastpresidential voteregistered remesas{
	tex ${lbe_`var'} & ${m`var'_0} & ${m`var'_1} & ${dif_`var'}${star_`var'}\\
	}
	tex \hline \hline
	tex \end{tabular}
	
//Create balance table for 7 day window

foreach var of varlist male age householdincome citysize education working voted_lastpresidential voteregistered remesas{
	
	reg `var' posttrump_7days
	global m`var'_0: di %6.3fc _b[_cons]
	global m`var'_1: di %6.3fc _b[_cons] + _b[posttrump_7days]
	global dif_`var': di %6.3fc _b[posttrump_7days]

	global lbe_`var' : var label `var'

	qui test posttrump_7days=0
	global p_`var': di %12.3fc r(p)
	glo star_`var'=cond(${p_`var'}<.001,"***",cond(${p_`var'}<.01,"**",cond(${p_`var'}<.05,"*",cond(${p_`var'}<.1,"+",""))))
}

//Output the results of the 7 day window balance test
	texdoc init balance_table_7days.tex, replace force
	tex \begin{tabular}{lccc} \toprule \toprule
	tex Variable			& 	Mean Control	& Mean Treatment & Difference \\
	tex \addlinespace \hline \\
	foreach var of varlist male age householdincome citysize education working voted_lastpresidential voteregistered remesas{
	tex ${lbe_`var'} & ${m`var'_0} & ${m`var'_1} & ${dif_`var'}${star_`var'}\\
	}
	tex \hline \hline
	tex \end{tabular}

//NOTE: Three .tex files will now be saved in your working directory. Please consult these files to see
//the three separate tables that were compiled to create Appendix Table B.5. 
	
	
*******************************
*******************************
//3. MAIN RESULTS IN FIGURE 2//
*******************************
*******************************


// Effects of Trump's election on Trust in the US Government 

// We start with the full sample, then show +/- 7 days restricted bandwidth, then restricted bandwidth plus covariates, 
//then entropy balancing weights (but not covariates, given that we already balanced on them). 
//All models include country fixed effects and city size fixed effects. 


eststo clear
// Panel A: Full Sample with Country FE and City Size FE
eststo m_1: reg trustusgov i.posttrump i.country i.citysize
eststo m_2: reg trustusgov i.posttrump##c.time_zero i.country i.citysize
local n1 = `e(N)'

// Panel B: 7 day bandwidth with Country FE and City Size FE
eststo m_3: reg trustusgov i.posttrump_7days i.country i.citysize
eststo m_4: reg trustusgov i.posttrump_7days##c.time_zero i.country i.citysize 
local n3 = `e(N)'

// Panel C: 7 day bandwidth with Country FE and City Size FE plus covariate adjustment
eststo m_5: reg trustusgov i.posttrump_7days i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered remesas 
eststo m_6: reg trustusgov i.posttrump_7days##c.time_zero i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered remesas 
local n5 = `e(N)'

// Panel D: 7 day bandwidth with Country FE, City Size FE, and entropy balancing weights
eststo m_7: svy: reg trustusgov i.posttrump_7days i.country i.citysize
eststo m_8: svy: reg trustusgov i.posttrump_7days##c.time_zero i.country i.citysize  
local n7 = `e(N)'

// Generate variable capturing the sample included in the main analyses
gen sample_reg = e(sample)

// Generate Figure 2

coefplot	(m_1, msize(medsmall)) (m_2, msize(medsmall) mcolor(gs9) ciopts(lcolor(gs9 gs9))) || ///
			(m_3, msize(medsmall)) (m_4, msize(medsmall)) || ///
			(m_5, msize(medsmall))  (m_6, msize(medsmall)) || ///
			(m_7, msize(medsmall)) (m_8, msize(medsmall)), ///
			drop(*.country *.citysize male age householdincome  education working  voted_lastpresidential voteregistered remesas _cons) xline(0, lpattern(solid)) byopts(row(2)) levels(95 90)	///
			bylabels("A. Full sample, N=`n1' " "B. ± 7 days, N=`n3' " "C. ± 7 days & Covariates, N=`n5' " "D. ± 7 days & Balancing, N=`n7' ") subtitle(, size(small)) nokey	///
			rename(1.posttrump = 1.posttrump_7days ///
			1.posttrump_14days = 1.posttrump_7days ///
			1.posttrump_21days = 1.posttrump_7days ///
			1.posttrump#c.time_zero = 1.posttrump_7days#c.time_zero ///
			1.posttrump_14days#c.time_zero = 1.posttrump_7days#c.time_zero ///
			1.posttrump_21days#c.time_zero = 1.posttrump_7days#c.time_zero) ///
			coeflabel(1.posttrump_7days = "Treatment"	///
			1.posttrump_7days#c.time_zero = "Treatment*Days" _cons = "Constant") ///
			aspect(.4) mlabgap(*2)   

addplot 1: , b1title("", size(small)) norescaling
addplot 2: , b1title("") norescaling
addplot 3: , b1title("Effect on Trust in US Gov't") norescaling
addplot 4: , b1title("Effect on Trust in US Gov't") norescaling

graph save Figure_1.gph, replace 
graph export Figure_1.png, replace 

drop sample_reg 

*Generate accompanying table, which is Appendix Table B.2

esttab m* using main.tex, ///
	drop(*.citysize *.country) unstack starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) ///
	cells(b(star fmt(%9.2f)) se(par)) stats(N, fmt(%9.0f %9.0g)) replace label ///
	mtitles("Full Sample" "\shortstack{Full Sample \\ with interaction}" "7 day bandwidth" ///
	"\shortstack{7 day bandwidth \\ with interaction}" "\shortstack{7 day bandwidth \\ and covariates}" ///
	"\shortstack{7 day bandwidth \\ and covariates \\ with interaction}" ///
	"\shortstack{7 day bandwidth \\ and entropy balancing}" "\shortstack{7 day bandwidth \\ and entropy balancing \\ with interaction}") ///
	nobaselevel collabels(, none) varlabels(_cons Constant) style(tex) prehead("\begin{tabular}{lcccccccc}" ///
	\hline\hline) posthead(\hline) prefoot(\hline) postfoot(\hline\hline ///
	\multicolumn{8}{l}{\footnotesize $+ p<0.10 * p<0.05 ** p<0.01 *** p<0.001.$ ///
	Standard errors in parentheses. All models include country and size of location fixed effects.}\\ "\end{tabular}" )
	
******************************************************
******************************************************
//4. Predicted Probabilities by Country for Figure 3//
******************************************************
******************************************************

//Predicted probabilities, calculated separately for each country, are based on are 7-day models (OLS) using covariates & size of location fixed effects

//Generate individual country graphs for Figure 3

//Dominican Republic
eststo dr: reg dummytrustusg posttrump_7days elsalv paraguay honduras i.citysize male age householdincome education working voted_lastpresidential voteregistered remesas
margins, at(posttrump_7days = (0 1) elsalv = 0 paraguay = 0 honduras = 0)
marginsplot, recast(scatter) xscale(range(-.5 1.5)) title("Dominican Republic") ytitle("") xlabel(0 "Before Election" 1 "After Election", labsize(vsmall)) xtitle("") aspect(2.5)

graph save predictedprob_DR.gph, replace 
graph export predictedprob_DR.png, replace 

//El Salvador
eststo es: reg dummytrustusg posttrump_7days elsalv paraguay honduras i.citysize male age householdincome education working voted_lastpresidential voteregistered remesas
margins, at(posttrump_7days = (0 1) elsalv = 1 paraguay = 0 honduras = 0)
marginsplot, recast(scatter) xscale(range(-.5 1.5)) title("El Salvador") ytitle("") xlabel(0 "Before Election" 1 "After Election", labsize(vsmall))  xtitle("") aspect(2.5)

graph save predictedprob_ES.gph, replace 
graph export predictedprob_ES.png, replace 

//Honduras
eststo hon: reg dummytrustusg posttrump_7days elsalv paraguay honduras i.citysize male age householdincome education working voted_lastpresidential voteregistered remesas
margins, at(posttrump_7days = (0 1) elsalv = 0 paraguay = 0 honduras = 1)
marginsplot, recast(scatter) xscale(range(-.5 1.5)) title("Honduras") ytitle("") xlabel(0 "Before Election" 1 "After Election", labsize(vsmall))  xtitle("") aspect(2.5)

graph save predictedprob_HON.gph, replace 
graph export predictedprob_HON.png, replace 

//Paraguay
eststo py: reg dummytrustusg posttrump_7days elsalv paraguay honduras i.citysize male age householdincome education working voted_lastpresidential voteregistered remesas
margins, at(posttrump_7days = (0 1) elsalv = 0 paraguay = 1 honduras = 0)
marginsplot, recast(scatter) xscale(range(-.5 1.5)) title("Paraguay") ytitle("") xlabel(0 "Before Election" 1 "After Election", labsize(vsmall))  xtitle("") aspect(2.5)

graph save predictedprob_PAR.gph, replace 
graph export predictedprob_PAR.png, replace 

//Combine individual country graphs for combined Figure 3
gr combine predictedprob_DR.gph predictedprob_ES.gph predictedprob_HON.gph predictedprob_PAR.gph, ycommon row(1)  l1("Predicted Probability") 

graph save predictedprob_combined.gph, replace
graph export predictedprob_combined.png, replace

*Output results for Figure 3 in table form

esttab dr using eachcountry.tex, ///
	drop(*.citysize ) unstack starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) ///
	cells(b(star fmt(%9.2f)) se(par)) stats(N, fmt(%9.0f %9.0g)) replace label ///
	mtitles("Trust in the US Government")  ///
	nobaselevel collabels(, none) varlabels(_cons Constant posttrump_7days "Post Trump, 7-day Window" citysize "City Size" male "Male" age "Age" ///
	householdincome "Household Income"  education "Education" working "Working" votedlast "Voted Last Presidential Election" ///
	voteregistered "Registered to Vote" remesas "Remittances" elsalv "El Salvador" paraguay "Paraguay" honduras "Honduras") style(tex) prehead("\begin{tabular}{lc}" ///
	\hline\hline) posthead(\hline) prefoot(\hline) postfoot(\hline\hline ///
	\multicolumn{2}{l}{\footnotesize $+ p<0.10 * p<0.05 ** p<0.01 *** p<0.001.$ ///
	Standard errors in parentheses. \\ All models include size of location fixed effects.}\\ "\end{tabular}" )
	
****************************************
****************************************
//5. Placebo tests for Figures 4 and 5//
****************************************
****************************************

**Placebo test 1 -- Faux election & FIGURE 4**

//Muñoz et al recommend a placebo test with a fictional 'treatment'
//First, we find the median date the control subjects were interviewed and then designate
//that date as the "treatment." Then, using only control subjects,
//we provide a placebo test for pre/post treatment differences

//Because fieldwork began on slightly different dates in each of our 4 countries, the
//median date is different across countries.

//These models use covariates, 7-day bandwidth, and country and size of location fixed effects.//
//As such, they are comparable to models reported in Panel C of Figure 2.//


//Create placebo variable by country
sum fecha if posttrump==0 & country==3, detail

//Among pre-treatment observations in El Salvador, the median interview data is 20759.//
//We call the median, "Placebo Election Day." That means our first post-treatment date is the median+1//
gen placebo=1 if fecha>20759 & fecha<=20766 & country==3
replace placebo=0 if fecha<=20759 & country==3

sum fecha if posttrump==0 & country==4, detail

//Among pre-treatment observations in Honduras, the median interview data is 20754.//
replace placebo=1 if fecha>20754 & fecha<=20766 & country==4
replace placebo=0 if fecha<=20754 & country==4

sum fecha if posttrump==0 & country==12, detail

//Among pre-treatment observations in Paraguay, the median interview data is 20762.//
replace placebo=1 if fecha>20762 & fecha<=20766 & country==12
replace placebo=0 if fecha<=20762 & country==12

sum fecha if posttrump==0 & country==21, detail

//Among pre-treatment observations in the Dominican Republic, the median interview data is 20756.//
replace placebo=1 if fecha>20756 & fecha<=20766 & country==21
replace placebo=0 if fecha<=20756 & country==21

//Create running time variable by country. We create a new time_zero variable, where zero is the median+1 date in each country

//Code the placebo time zero variable for El Salvador
gen placebo_time_zero=.
replace placebo_time_zero=fecha-20760 if country==3

//Code the placebo time zero variable for Honduras
replace placebo_time_zero=fecha-20755 if country==4

//Code the placebo time zero variable for Paraguay
replace placebo_time_zero=fecha-20763 if country==12

//Code the placebo time zero variable for the Dominican Republic
replace placebo_time_zero=fecha-20757 if country==21

//Generate a 7-day placebo bandwidth
gen placebo_7days=.
replace placebo_7days=0 if placebo==0 & placebo_time_zero<=6 & placebo_time_zero>=-7 
replace placebo_7days=1 if placebo==1 & placebo_time_zero<=6 & placebo_time_zero>=-7 
label var placebo_time_zero "Days"

//Run the placebo test. All models include a running time variable interaction, as with our main models.
 
eststo clear

//Fake Election Placebo Test, Naive  

eststo m_1: reg trustusgov i.placebo_7days
eststo m_2: reg trustusgov i.placebo_7days##c.placebo_time_zero

//Fake Election Placebo Test, Fixed Effects Only

eststo m_3: reg trustusgov i.placebo_7days i.country i.citysize
eststo m_4: reg trustusgov i.placebo_7days##c.placebo_time_zero i.country i.citysize

//Fake Election Placebo Test, Fixed Effects Plus Covariate Adjustment

eststo m_5: reg trustusgov i.placebo_7days i.country i.citysize male age education working voted_last household voteregistered remesas
eststo m_6: reg trustusgov i.placebo_7days##c.placebo_time_zero i.country i.citysize male age education working voted_last household voteregistered remesas

//Generate variable capturing the sample included in the main analyses
gen sample_reg = e(sample)

//Generate Figure 4

coefplot	(m_1, msize(medsmall)) (m_2, msize(medsmall) mcolor(gs9) ciopts(lcolor(gs9 gs9))) || ///
			(m_3, msize(medsmall)) (m_4, msize(medsmall)) || ///
			(m_5, msize(medsmall))  (m_6, msize(medsmall)) ,  ///
			drop(*.country *.citysize male age householdincome citysize education working  voted_lastpresidential voteregistered remesas _cons) xline(0, lpattern(solid)) byopts(row(1)) levels(95 90)	///
			bylabels("A. ± 7 days, Naive" "B. ± 7 days, FE" "C. ± 7 days, FE & Covariates") subtitle(, size(small)) nokey	///
			coeflabel(1.placebo_7days = "Placebo Election"	///
			1.placebo_7days#c.placebo_time_zero = "Placebo Election*Days" _cons = "Constant") ///
			aspect(.4) mlabgap(*2) 

addplot 1: , b1title("Effect on Trust in US Gov't", size(small)) norescaling
addplot 2: , b1title("Effect on Trust in US Gov't") norescaling
addplot 3: , b1title("Effect on Trust in US Gov't") norescaling

graph save Figure_placebo2.gph, replace 
graph export Figure_placebo2.png, replace 

*Generate accompanying table, which is Appendix Table B.6.

esttab m* using placebo_fakeelection.tex, ///
	drop(*.citysize *.country) unstack starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) ///
	cells(b(star fmt(%9.2f)) se(par)) stats(N, fmt(%9.0f %9.0g)) replace label ///
	mtitles("± 7 Days" "\shortstack{± 7 Days \\ with interaction}" "± 7 Days, Fixed Effects" ///
	"\shortstack{± 7 Days, Fixed Effects \\ with interaction}" "\shortstack{± 7 Days,\\ Cov. Adj.}" ///
	"\shortstack{± 7 Days,\\ Cov. Adj. \\ with interaction}") ///
	nobaselevel collabels(, none) varlabels(_cons Constant) style(tex) prehead("\begin{tabular}{lcccccc}" ///
	\hline\hline) posthead(\hline) prefoot(\hline) postfoot(\hline\hline ///
	\multicolumn{7}{l}{\footnotesize $+ p<0.10 * p<0.05 ** p<0.01 *** p<0.001.$ ///
	Standard errors in parentheses. All models include country and size of location fixed effects.}\\ "\end{tabular}" )
 
drop sample_reg


** Placebo test 2: trust in other foreign entities for Figure 5 **

//These models use covariates, 7-day bandwidth, and country and size of location fixed effects.//
//As such, they are comparable to models reported in Panel C of Figure 2.//

eststo clear

//Trust in China
eststo m_1: reg trustchina i.posttrump_7days i.country i.citysize male age education working voted_last household voteregistered remesas
eststo m_2: reg  trustchina i.posttrump_7days##c.time_zero i.country i.citysize

//Trust in United Nations
eststo m_3: reg trustun i.posttrump_7days i.country i.citysize male age education working voted_last household voteregistered remesas
eststo m_4: reg  trustun i.posttrump_7days##c.time_zero i.country i.citysize male age education working voted_last household voteregistered remesas

//Trust in Organization of American States
eststo m_5: reg trustoas i.posttrump_7days i.country i.citysize male age education working voted_last household voteregistered remesas
eststo m_6: reg trustoas i.posttrump_7days##c.time_zero i.country i.citysize male age education working voted_last household voteregistered remesas

//Generate variable capturing the sample included in the main analyses
gen sample_reg = e(sample)

//Generate Figure 5

coefplot	(m_1, msize(medsmall)) (m_2, msize(medsmall) mcolor(gs9) ciopts(lcolor(gs9 gs9))) || ///
			(m_3, msize(medsmall)) (m_4, msize(medsmall)) || ///
			(m_5, msize(medsmall))  (m_6, msize(medsmall)) ,  ///
			drop(*.country *.citysize male age householdincome citysize education working  voted_lastpresidential voteregistered remesas _cons) xline(0, lpattern(solid)) byopts(row(1)) levels(95 90)	///
			bylabels("A. Trust China, ± 7 days" "B. Trust UN, ± 7 days" "C. Trust OAS, ± 7 days") subtitle(, size(small)) nokey	///
			coeflabel(1.posttrump_7days = "Treatment group"	///
			1.posttrump_7days#c.time_zero = "Treatment*Days" _cons = "Constant") ///
			aspect(.6) mlabgap(*2)
			
addplot 1: , b1title("Effect on Trust", size(small)) norescaling
addplot 2: , b1title("Effect on Trust") norescaling
addplot 3: , b1title("Effect on Trust") norescaling

graph save Figure_placebo.gph, replace 
graph export Figure_placebo.png, replace 

*Generate accompanying table, which is Appendix Table B.7.

esttab m* using placebo_foreigngovs.tex, ///
	drop(*.citysize *.country) unstack starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) ///
	cells(b(star fmt(%9.2f)) se(par)) stats(N, fmt(%9.0f %9.0g)) replace label ///
	mtitles("Trust in China" "\shortstack{Trust in China \\ with interaction}" "Trust in UN" ///
	"\shortstack{Trust in UN \\ with interaction}" "\shortstack{Trust in OAS}" ///
	"\shortstack{Trust in OAS \\ with interaction}") ///
	nobaselevel collabels(, none) varlabels(_cons Constant) style(tex) prehead("\begin{tabular}{lcccccc}" ///
	\hline\hline) posthead(\hline) prefoot(\hline) postfoot(\hline\hline ///
	\multicolumn{7}{l}{\footnotesize $+ p<0.10 * p<0.05 ** p<0.01 *** p<0.001.$ ///
	Standard errors in parentheses. All models include country and size of location fixed effects.}\\ "\end{tabular}" )
	
drop sample_reg

*************************************
*************************************
//6. Appendix A: Tables and Figures//
*************************************
*************************************

*Table A.1. Interview Dates by Country

//Table A.1 is based on the following results: 
sum fecha if paraguay==1
sum fecha if elsalv==1
sum fecha if hond==1
sum fecha if dr==1

*Figure A.1. Interviews per Day

//NOTE: Figure A.1. was created by hand using Adobe Illustrator,
//based on histograms created in Stata. The code for the histograms is here:

hist fecha if paraguay==1, w(1)
hist fecha if dr==1, w(1)
hist fecha if elsalv==1, w(1)
hist fecha if honduras==1, w(1)

*Table A.2 Summary Statistics

estpost summarize citysize age male ideology voteregistered voted_last trustchina trustusgov trustoas trustun education working householdincome remesas emigrate 
esttab using summarystats.csv, nobaselevels b(2) se(2) cells("mean(fmt(2)) sd(fmt(2)) min(fmt(0)) max(fmt(0))")  mtitles("Mean" "Standard Deviation" "Minimum" "Maximum") label nogaps replace 

*Tables A.3, A.4, and A.5 and Figures A.2 and A.3 are based on the authors' analysis of Latin American media coverage

*Table A.6 Top 25 Google Search Terms by Country, Nov. 9, 2016

//Table A.6 reports the top Google search terms in each country on Nov. 9, 2016.
//The authors obtained this data from Google search trends. Google search trends are based on random sampling
//of Google data, so the online interface returns slightly different results each time it is queried.
//The specific .csv files that were used to construct Table A.6 can be found in the "Top Google Search terms"
//folder in our replication package. There is a separate .csv file for each country.

*Figure A.4 Daily Google Searches for "trump" and "clinton," Oct. 1 - Dec. 1, 2016

//Figure A.4 was created by hand using Excel and Adobe Illustrator. 
//Figure A.4 is based on Google search data from Oct. 1 - Dec. 1, 2016. 
//Google search trends are based on random sampling of Google data, so the online 
//interface returns slightly different results each time it is queried.
//The specific .csv files used to construct this figure can be found in the "Google Searches for Clinton and Trump"
//folder in our replication package. There is a separate .csv file for each country. 
 
*Figure A.5 Estimated Percentages with a Good or Very Good Opinion of the US, Latinobarometro Data

//Figure A.5 was made in Excel, based on summary statistics obtained from the Latinobarometro online data 
//tool. The underlying data and the graph can be access in the Excel file included in our replication package.


*Table A.7. No Relationship Between Size of Location and Trust in the US Government

mean trustusgov, over(citysize)
esttab, cells(b(fmt(2)) ci(fmt(2) par) )   mtitles("Mean Estimated Level of Trust in the US Government" "95% confidence interval") label nogaps replace 

*Table A.8 Size of location and trust in the US government

eststo clear
eststo m_1: reg trustusgov citysize
eststo m_2: reg trustusgov citysize i.country
eststo m_3: reg trustusgov citysize i.country male age householdincome education working  voted_lastpresidential voteregistered remesas 

coefplot (m_1, label(Bivariate Model)) ///
(m_2, label(+ Country Fixed Effects)) ///
(m_3, label(+ Covariates)) ///
, keep(citysize) xline(0)

graph export citysize_OLS.pdf, replace
		
esttab using table1_citysize.csv, nobaselevels b(3) se(3) starlevels(* 0.05 ** 0.01  *** 0.001 ) mtitles("No Controls" "+Country FEs" "+Covariates") constant label nogaps replace 

*Figure A.6 Main Results with Province Fixed Effects 

//The code below repeats our main analysis (Figure 2) with fixed effects by province. 
//The results remain unchanged.

eststo clear
//Panel A: Full Sample with Country FE and City Size FE and Province FE
eststo m_1: reg trustusgov i.posttrump i.country i.citysize i.prov
eststo m_2: reg trustusgov i.posttrump##c.time_zero i.country i.citysize i.prov
local n1 = `e(N)'

//Panel B: 7 day bandwidth with Country FE and City Size FE and Province FE
eststo m_3: reg trustusgov i.posttrump_7days i.country i.citysize i.prov
eststo m_4: reg trustusgov i.posttrump_7days##c.time_zero i.country i.citysize i.prov
local n3 = `e(N)'

//Panel C: 7 day bandwidth with Country FE and City Size FE and Province FE plus covariate adjustment
eststo m_5: reg trustusgov i.posttrump_7days i.country i.citysize i.prov male age householdincome education working  voted_lastpresidential voteregistered remesas 
eststo m_6: reg trustusgov i.posttrump_7days##c.time_zero i.country i.citysize i.prov male age householdincome education working  voted_lastpresidential voteregistered remesas 
local n5 = `e(N)'

//Panel D: 7 day bandwidth with Country FE, City Size FE, Province FE and entropy balancing weights
eststo m_7: svy: reg trustusgov i.posttrump_7days i.country i.citysize i.prov
eststo m_8: svy: reg trustusgov i.posttrump_7days##c.time_zero i.country i.citysize i.prov
local n7 = `e(N)'

//Generate variable capturing the sample included in the main analyses
gen sample_reg = e(sample)

//Generate Figure A.6

coefplot	(m_1, msize(medsmall)) (m_2, msize(medsmall) mcolor(gs9) ciopts(lcolor(gs9 gs9))) || ///
			(m_3, msize(medsmall)) (m_4, msize(medsmall)) || ///
			(m_5, msize(medsmall))  (m_6, msize(medsmall)) || ///
			(m_7, msize(medsmall)) (m_8, msize(medsmall)), ///
			drop(*.country *.citysize *.prov male age householdincome  education working  voted_lastpresidential voteregistered remesas _cons) xline(0, lpattern(solid)) byopts(row(2)) levels(95 90)	///
			bylabels("A. Full sample, N=`n1' " "B. ± 7 days, N=`n3' " "C. ± 7 days & Covariates, N=`n5' " "D. ± 7 days & Balancing, N=`n7' ") subtitle(, size(small)) nokey	///
			rename(1.posttrump = 1.posttrump_7days ///
			1.posttrump_14days = 1.posttrump_7days ///
			1.posttrump_21days = 1.posttrump_7days ///
			1.posttrump#c.time_zero = 1.posttrump_7days#c.time_zero ///
			1.posttrump_14days#c.time_zero = 1.posttrump_7days#c.time_zero ///
			1.posttrump_21days#c.time_zero = 1.posttrump_7days#c.time_zero) ///
			coeflabel(1.posttrump_7days = "Treatment"	///
			1.posttrump_7days#c.time_zero = "Treatment*Days" _cons = "Constant") ///
			aspect(.4) mlabgap(*2)   

addplot 1: , b1title("", size(small)) norescaling
addplot 2: , b1title("") norescaling
addplot 3: , b1title("Effect on Trust in US Gov't") norescaling
addplot 4: , b1title("Effect on Trust in US Gov't") norescaling

graph save Figure_MainResultsProvFE.gph, replace 
graph export Figure_MainResultsProvFE.png, replace 

drop sample_reg 

	
*Table A.9. Ideology as an Additional Covariate
	
eststo clear
eststo m_1: reg trustusgov i.posttrump_7days i.country i.citysize ideology male age householdincome education working  voted_lastpresidential voteregistered remesas 
eststo m_2: reg trustusgov i.posttrump_7days##c.time_zero i.country i.citysize ideology male age householdincome education working  voted_lastpresidential voteregistered remesas 

coefplot (m_1, label(7-day window w/ Covariates)) ///
(m_2, label(+ Interaction Term)) ///
, keep(ideology) xline(0) xlabel(0(.01).05)

	graph export ideology_mainmodels.pdf, replace
		
esttab using ideology.csv, nobaselevels b(3) se(3) starlevels(* 0.05 ** 0.01 *** 0.001 ) mtitles("7-day window w/ Covariates" "+ Interaction Term") constant label nogaps replace 


*Table A.10. Heterogeneous Effects by Ideology	

eststo clear

eststo m_1: reg trustusgov posttrump_7days i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered remesas if ideology<6
eststo m_2: reg trustusgov posttrump_7days i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered remesas if ideology>5

coefplot (m_1, label(Liberal Respondents)) ///
(m_2, label(Conservative Respondents)) ///
, keep(posttrump_7days) xline(0)

	graph export ideology_HTE.pdf, replace
		
esttab using ideology_HTE.csv, nobaselevels b(3) se(3) starlevels(* 0.05 ** 0.01  *** 0.001 ) mtitles("Liberal Respondents" "Conservative Respondents") constant label nogaps replace 


*Table A.11. Intent to Emigrate as an Additional Covariate

eststo clear
eststo m_1: reg trustusgov i.posttrump_7days i.country i.citysize emigrate remesas male age householdincome education working  voted_lastpresidential voteregistered 
eststo m_2: reg trustusgov i.posttrump_7days##c.time_zero i.country i.citysize emigrate remesas male age householdincome education working  voted_lastpresidential voteregistered 

esttab using table1_emigrate.csv, nobaselevels b(3) se(3) starlevels(* 0.05 ** 0.01 *** 0.001 ) mtitles("7 Day Window w/Covariates" "+Interaction") constant label nogaps replace 

//In Appendix A we discuss how the emigration variable is well-balanced across our pre- and post-election respondents, and how in our sample remittance recipients tend to express more trust in the US government. 
//The code below reproduces those findings and others that we mention in the text of Appendix A. 

ttest remesas, by(posttrump)
ttest emigrate, by(posttrump)

gen rem_emigrate=.
replace rem_emigrate=0 if emigrate==0
replace rem_emigrate=0 if remesas==0
replace rem_emigrate=1 if remesas==1 & emigrate==1

sum rem_emigrate
ttest rem_emigrate, by(posttrump)

reg trustusgov remesas
reg trustusgov emigrate
reg trustusgov rem_emigrate

ttest dummytrustus, by(remesas)
ttest dummytrustus, by(emigrate)

sum remesas if elsalv==1
sum remesas if dr==1
sum remesas if honduras==1
sum remesas if paraguay==1

sum emigrate if elsalv==1
sum emigrate if dr==1
sum emigrate if honduras==1
sum emigrate if paraguay==1


*Table A.12. Heterogenous Effects by Ties to US, 7-day bandwidth

eststo clear

eststo m_1: reg trustusgov posttrump_7days i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered if remesas==0 & emigrate==0
eststo m_2: reg trustusgov posttrump_7days i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered if remesas==1
eststo m_3: reg trustusgov posttrump_7days i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered if emigrate==1
eststo m_4: reg trustusgov posttrump_7days i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered if rem_emigrate==1


coefplot (m_1, label(No Ties to US)) ///
(m_2, label(Gets Remittances)) ///
(m_3, label(Wants to Emigrate)) ///
(m_4, label(Remittances & Emigrate)) ///
, keep(posttrump) xline(0) xlabel(-.5(.1)0)

	graph export USties_7day.pdf, replace
		
esttab using USties_7day.csv, nobaselevels b(3) se(3) starlevels(* 0.05 ** 0.01  *** 0.001 ) mtitles("No Ties to US" "Gets Remittances" "Wants to Emigrate" "Remittances & Emigrate") constant label nogaps replace 


*Table A.13. Heterogenous Effects by Ties to US, Full Sample

eststo clear
eststo m_1: reg trustusgov posttrump i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered if remesas==0 & emigrate==0
eststo m_2: reg trustusgov posttrump i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered if remesas==1
eststo m_3: reg trustusgov posttrump i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered if emigrate==1
eststo m_4: reg trustusgov posttrump i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered if rem_emigrate==1
		
esttab using USties_fullsample.csv, nobaselevels b(3) se(3) starlevels(* 0.05 ** 0.01  *** 0.001 ) mtitles("No Ties to US" "Gets Remittances" "Wants to Emigrate" "Remittances & Emigrate") constant label nogaps replace 

*************************************
*************************************
//7. Appendix B: Tables and Figures//
*************************************
*************************************
	
*Table B.1. Descriptive Statistics Summarizing the Decline in Trust in the US Gov’t
	
foreach var of varlist dummytrustusg{
	
	reg `var' posttrump_7days
	global m`var'_0: di %6.3fc _b[_cons]
	global m`var'_1: di %6.3fc _b[_cons] + _b[posttrump_7days]
	global dif_`var': di %6.3fc _b[posttrump_7days]

	global lbe_`var' : var label `var'

	qui test posttrump_7days=0
	global p_`var': di %12.3fc r(p)
	glo star_`var'=cond(${p_`var'}<.001,"***",cond(${p_`var'}<.01,"**",cond(${p_`var'}<.05,"*",cond(${p_`var'}<.1,"+",""))))
}

//Output the results of the balance test
	texdoc init dummytrustusg.tex, replace force
	tex \begin{tabular}{lccc} \toprule \toprule
	tex Variable			& 	Mean Control	& Mean Treatment & Difference \\
	tex \addlinespace \hline \\
	foreach var of varlist dummytrustusg{
	tex ${lbe_`var'} & ${m`var'_0} & ${m`var'_1} & ${dif_`var'}${star_`var'}\\
	}
	tex \hline \hline
	tex \end{tabular}


*Table B.2. Effect of Trump’s Election on Trust in the US Government

//These are the main results from Figure 2 in table form.
//See code for Main Results in Figure 2 above to produce this table. 
	
	
*Table B.3. Effect of Trump’s Election by Country

eststo clear
* Panel A: Dominican Rep 7 day bandwidth with City Size FE plus covariate adjustment
eststo m_1: reg trustusgov i.posttrump_7days i.citysize male age householdincome education working  voted_lastpresidential voteregistered remesas if dr==1

* Panel B: Paraguay 7 day bandwidth with City Size FE plus covariate adjustment
eststo m_2: reg trustusgov i.posttrump_7days i.citysize male age householdincome education working  voted_lastpresidential voteregistered remesas if paraguay==1

* Panel C: El Salvador 7 day bandwidth with City Size FE plus covariate adjustment
eststo m_3: reg trustusgov i.posttrump_7days i.citysize male age householdincome education working  voted_lastpresidential voteregistered remesas if elsalv==1

* Panel D: Honduras 7 day bandwidth with City Size FE plus covariate adjustment
eststo m_4: reg trustusgov i.posttrump_7days i.citysize male age householdincome education working  voted_lastpresidential voteregistered remesas if honduras==1

esttab using appendixb2.csv, nobaselevels b(3) se(3) starlevels(+ 0.1 * 0.05 ** 0.01 *** 0.001 ) mtitles("Dominican Republic" "Paraguay" "El Salvador" "Honduras") constant label nogaps replace 

esttab using appendixb2.tex, nobaselevels b(3) se(3) starlevels(+ 0.1 * 0.05 ** 0.01 *** 0.001 ) drop(*.citysize) mtitles("Dominican Republic" "Paraguay" "El Salvador" "Honduras")  constant label nogaps replace 


*Table B.4. Covariate Distribution

eststo clear
estpost summarize elsalv honduras dr paraguay citysize male age householdincome education working voted_lastpresidential voteregistered remesas if posttrump==1, detail
esttab using appendixB31.csv, cells("mean Var skewness") replace

eststo clear
estpost summarize elsalv honduras dr paraguay citysize male age householdincome education working voted_lastpresidential voteregistered remesas if posttrump==0, detail
esttab using appendixB32.csv, cells("mean Var skewness") replace


*Table B.5. Covariate Balance Tests, 7-Day Bandwidth Intervals*

//See code for Figure 1 above to produce this table.  



*Table B.6. Placebo Tests: Simulating a ‘Faux Election’

//See code for Figure 4 above to produce this table. 


*Table B.7. Placebo Tests: Trust in Foreign Governments and Organizations

//See code for Figure 5 above to produce this table. 


*Figure B.1. Power calculations with different bandwidths

// Generate matrix that includes the power and number of units in the treatment and control groups for two differnt effect sizes and multiple bandwidths

matrix results = J(24,5,.)
matrix colnames results =  bandwidth n_contr n_treat  pow_eightsd pow_fifthsd
local i 0 
forval d = 0/23{
	if `d' == 0{
		local d_neg = -1
	}
	if `d' != 0{
				local d_neg = (`d'+1) * -1 
	}
	gen treatment_band = . 
	replace treatment_band = 1 if time_zero >= 0 & time_zero <= `d' 
	replace treatment_band = 0 if time_zero < 0 & time_zero >= `d_neg'
	replace treatment_band = . if missing(male, age, householdincome, citysize, education, working, voted_lastpresidential, voteregistered, remesas)								 
	local ++ i 
	local bandwidth = `d' + 1 
	qui: sum treatment_band if treatment_band == 1 
	local n_treat = r(N)
	qui: sum treatment_band if treatment_band == 0 
	local n_contr = r(N)
	sum trustusgov if treatment_naive == 0 
	local sd = r(sd) 
	local mean = r(mean)
	local eight = `sd' / 8
	local fifth = `sd' / 5
	local eightsd = `mean' + `eight'
	local fifthsd = `mean' + `fifth'
	power twomeans `mean' `eightsd', sd(`sd') n1(`n_contr') n2(`n_treat') 
	local pow_fifthsd = r(power)
	power twomeans `mean' `fifthsd', sd(`sd') n1(`n_contr') n2(`n_treat')
	local pow_eightsd = r(power)	
	matrix results[`i', 1] = `bandwidth',`n_contr',`n_treat',`pow_fifthsd',`pow_eightsd'
	drop treatment_band
} 

//Transform matrix into variables
svmat results, names(col)

//Total height of histogram bars
gen tot_contr = n_treat + n_contr

//Generate Figure B.1

graph twoway	(bar tot_contr bandwidth, fcolor(gs4) ///
				yaxis(2) ylabel(0(1000)6000, labsize(vsmall) axis(2)) ytitle("Number of valid cases in treatment and control groups", axis(2) size(vsmall)) ///
				yscale(axis(2) alt)) ///
				(rbar tot_contr n_treat bandwidth, fcolor(gs13) lcolor(gs1)  lwidth(vthin) yaxis(2)) ///
				(function y=.8, ra(0 24) lpattern(solid) lcolor(red) lwidth(vthin)) ///
				(line pow_fifthsd bandwidth, lcolor(black) lpattern(solid) lcolor(black) yaxis(1) yscale(axis(1) alt)) ///
				(line pow_eightsd bandwidth, lpattern(dash) lcolor(black) yaxis(1) ///
				ytitle("Power", size(vsmall)) ylabel(0(.2)1, labsize(vsmall) gmin gmax axis(1)) ///
				xtitle("Bandwidth (± days) around Trump's election", size(vsmall))  xlabel(0(3)24, labsize(vsmall)) ///
				legend(ti("Effect size", size(vsmall)) order(4 "1/5 standard deviation change" 5 "1/8 standard deviation change") size(vsmall) rows(1) pos(6)))

//Save Figure B.1 and drop extra variables

graph save powercalcs.gph, replace
graph export powercalcs.png, replace

drop bandwidth n_contr n_treat pow_fifthsd pow_eightsd tot_contr


*Figure B.2. Effects of Trump’s election across all possible bandwidths

//Generate matrix that includes the effect estimates and the number of units in the treatment and control groups for multiple bandwidths
local i 0 
matrix results = J(24,8,.)
matrix colnames results = bandwidth coef ll95 ul95 ll90 ul90 n_treat n_contr
forval d = 0/23{
	if `d' == 0{
		local d_neg = -1
	}
	if `d' != 0{
		local d_neg = (`d'+1) * -1 
	}
	gen treatment_band = . 
	replace treatment_band = 1 if time_zero >= 0 & time_zero <= `d'
	replace treatment_band = 0 if time_zero < 0 & time_zero >= `d_neg'
	replace treatment_band = . if fecha < 20767 & fecha >= 20767
	local bandwidth = `d' + 1 
	quietly: reg trustusgov i.treatment_band
	local ++ i 
	local coef = _b[1.treatment_band]
	local degrees = e(df_r)
	local critical_5 = invttail(`degrees', 0.025)
	local se = _se[1.treatment_band]
	local confvalue_5 = `critical_5' * `se'
	local critical_10 = invttail(`degrees', 0.05)
	local confvalue_10 = `critical_10' * `se'
	local ll95 = `coef' - `confvalue_5'
	local ul95 = `coef' + `confvalue_5'
	local ll90 = `coef' - `confvalue_10'
	local ul90 = `coef' + `confvalue_10'
	qui: sum treatment_band if treatment_band == 1
	local n_treat = r(N)
	qui: sum treatment_band if treatment_band == 0 
	local n_contr = r(N)
	matrix results[`i', 1] = `bandwidth',`coef',`ll95',`ul95',`ll90',`ul90',`n_treat',`n_contr'
	drop treatment_band
} 

//Transform matrix into variables
svmat results, names(col)

//Calculate total height of histogram bars
gen tot_contr = n_treat + n_contr

//Generate Figure B.2

graph twoway	(bar tot_contr bandwidth, fcolor(gs4) ///
				yaxis(2) ylabel(0(1000)6000, labsize(vsmall) axis(2)) ytitle("Number of cases in treatment and control groups", axis(2) size(vsmall)) ///
				yscale(axis(2) alt)) ///
				(rbar tot_contr n_treat bandwidth, fcolor(gs13) lcolor(gs1)  lwidth(vthin) yaxis(2) legend(off)) ///
				(function y=0, ra(0 24) lstyle(solid) lcolor(red) lwidth(vthin)) ///
				(rspike ll95 ul95 bandwidth, lwidth(0.2) lcolor(black) yaxis(1) yscale(axis(1) alt)) ///
				(rspike ll90 ul90 bandwidth, lwidth(0.4) lcolor(black) yaxis(1)) ///
				(scatter coef bandwidth, msymbol(O) mcolor(black) yaxis(1) ///
				ytitle("Effects on Trust in US Gov't", size(vsmall)) ylabel(, labsize(vsmall) axis(1)) ///
				xtitle("Bandwidth (± days) around election", size(vsmall)) xlabel(0(3)24, labsize(vsmall)) legend(off))

graph save multiplebandwidths.gph, replace
graph export multiplebandwidths.png, replace

//Drop variables generated from matrix
drop bandwidth coef ll95 ul95 ll90 ul90 n_treat n_contr tot_contr


*Figure B.3. Covariate Balance Tests, 3-Day Bandwidth Intervals

//Create matrix for each 3-day bandwidth
clear matrix
foreach var of varlist treatment_naive  posttrump_21days posttrump_18days posttrump_15days posttrump_12days posttrump_9days posttrump_6days  posttrump_3days {
	gen r_`var' = `var'
	recode r_`var' (1=0) (0=1)
}

//Conduct t-test and store results in matrix to generate the plot
foreach tr of varlist  treatment_naive  posttrump_21days posttrump_18days posttrump_15days posttrump_12days posttrump_9days posttrump_6days  posttrump_3days {
	matrix mean = J(1,9,.)
	matrix colnames mean =  male age householdincome citysize education working voted_lastpresidential voteregistered remesas 
	matrix CI = J(8,9,.)
	matrix colnames CI =  male age householdincome citysize education working  voted_lastpresidential voteregistered remesas 
	matrix rownames CI = ll95 ul95 ll90 ul90
	local i 0
	foreach var of varlist  male age householdincome citysize education working  voted_lastpresidential voteregistered remesas {
		quietly: ttest `var', by(`tr') 
		local ++ i 
		local diff =  r(mu_2) - r(mu_1) 
		matrix mean[1, `i'] = `diff' 
		local degrees = r(df_t)
		local critical_5 = invttail(`degrees', 0.025)
		local confvalue_5 = `critical_5' * r(se)
		local critical_10 = invttail(`degrees', 0.05)
		local confvalue_10 = `critical_10' * r(se)
		local ll95 = `diff' - `confvalue_5'
		local ul95 = `diff' + `confvalue_5'
		local ll90 = `diff' - `confvalue_10'
		local ul90 = `diff' + `confvalue_10'
		matrix CI[1, `i'] = `ll95' \ `ul95' \ `ll90' \ `ul90'
	}
matrix `tr'_m = mean
matrix `tr'_CI = CI
}

//Generate Figure B.3 from results stored in matrices 
label var working "Working"
label var voteregistered "Registered to Vote"
label var voted_lastpresidential "Voted Last Presidential Election"
label var remesas "Remittances"

coefplot (matrix(treatment_naive_m), xline(0) ci((treatment_naive_CI[1] treatment_naive_CI[2]) (treatment_naive_CI[3] treatment_naive_CI[4]))) ///
		|| (matrix(posttrump_21days_m), xline(0, lpattern(solid)) ci((posttrump_21days_CI[1] posttrump_21days_CI[2]) (posttrump_21days_CI[3] posttrump_21days_CI[4]))) ///
		|| (matrix(posttrump_18days_m), xline(0, lpattern(solid)) ci((posttrump_18days_CI[1] posttrump_18days_CI[2]) (posttrump_18days_CI[3] posttrump_18days_CI[4]))) ///
		|| (matrix(posttrump_15days_m), xline(0, lpattern(solid)) ci((posttrump_15days_CI[1] posttrump_15days_CI[2]) (posttrump_15days_CI[3] posttrump_15days_CI[4]))) ///
		|| (matrix(posttrump_12days_m), xline(0, lpattern(solid)) ci((posttrump_12days_CI[1] posttrump_12days_CI[2]) (posttrump_12days_CI[3] posttrump_12days_CI[4]))) ///
		|| (matrix(posttrump_9days_m), xline(0, lpattern(solid)) ci((posttrump_9days_CI[1] posttrump_9days_CI[2]) (posttrump_9days_CI[3] posttrump_9days_CI[4]))) ///
		|| (matrix(posttrump_6days_m), xline(0, lpattern(solid)) ci((posttrump_6days_CI[1] posttrump_6days_CI[2]) (posttrump_6days_CI[3] posttrump_6days_CI[4]))) ///
		|| (matrix(posttrump_3days_m), xline(0, lpattern(solid)) ci((posttrump_3days_CI[1] posttrump_3days_CI[2]) (posttrump_3days_CI[3] posttrump_3days_CI[4]))) ///
		, byopts(row(2)) xlabel(-1.5(1)1.5) ylabel(, labsize(small)) xscale(range(-1 1.5)) xline(0, lpattern(solid))  ///
			nokey nooffset bylabels("Full sample" "± 21 days" "± 18 days" "± 15 days" "± 12 days" "± 9 days" "± 6 days" "± 3 days") rescale(male remesas  voted_lastpresidential voteregistered =20 working =-10 citysize=2 ) xtitle("Mean Difference Between Treatment and Control Groups with 90% and 95% Confidence Intervals")

//Save Figure B.3			
graph save balancetests_expanded.gph, replace 
graph export balancetests_expanded.png, replace 


*Figure B.4. Mean Trust in US Government by Date (4-Point Scale) 

//A reviewer requested that we plot the mean DV by date. While the code below generates that
//figure, we caution against drawing substantive conclusions from it. 
//The confidence intervals on the daily means are enormous, and the N varies wildly from 
//1 to 250+. Moreover, we know different countries have different levels of trust in the 
//US government, and a different number of people from each country were interviewed on each
//day.

//We plot the mean DVs by date with 95% confidence intervals.

//Figure B.4 uses the 4-pt DV while Figure B.5 uses the binary DV.
//Black circles are dates before the US election results were known, including election day.
//Maroon squares are dates after the US election, starting with Nov. 9, 2016.

eststo clear

eststo m_1: mean trustusgov if fecha==20741
eststo m_2: mean trustusgov if fecha==20742
eststo m_3: mean trustusgov if fecha==20743
eststo m_4: mean trustusgov if fecha==20744
eststo m_5: mean trustusgov if fecha==20745
eststo m_6: mean trustusgov if fecha==20746
eststo m_7: mean trustusgov if fecha==20747
eststo m_8: mean trustusgov if fecha==20748
eststo m_9: mean trustusgov if fecha==20749
eststo m_10: mean trustusgov if fecha==20750

eststo m_11: mean trustusgov if fecha==20751
eststo m_12: mean trustusgov if fecha==20752
eststo m_13: mean trustusgov if fecha==20753
eststo m_14: mean trustusgov if fecha==20754
eststo m_15: mean trustusgov if fecha==20755
eststo m_16: mean trustusgov if fecha==20756
eststo m_17: mean trustusgov if fecha==20757
eststo m_18: mean trustusgov if fecha==20758
eststo m_19: mean trustusgov if fecha==20759
eststo m_20: mean trustusgov if fecha==20760

eststo m_21: mean trustusgov if fecha==20761
eststo m_22: mean trustusgov if fecha==20762
eststo m_23: mean trustusgov if fecha==20763
eststo m_24: mean trustusgov if fecha==20764
eststo m_25: mean trustusgov if fecha==20765
eststo m_26: mean trustusgov if fecha==20766
eststo m_27: mean trustusgov if fecha==20767
eststo m_28: mean trustusgov if fecha==20768
eststo m_29: mean trustusgov if fecha==20769
eststo m_30: mean trustusgov if fecha==20770

eststo m_31: mean trustusgov if fecha==20771
eststo m_32: mean trustusgov if fecha==20772
eststo m_33: mean trustusgov if fecha==20773
eststo m_34: mean trustusgov if fecha==20774
eststo m_35: mean trustusgov if fecha==20775
eststo m_36: mean trustusgov if fecha==20776
eststo m_37: mean trustusgov if fecha==20777
eststo m_38: mean trustusgov if fecha==20778
eststo m_39: mean trustusgov if fecha==20779
eststo m_40: mean trustusgov if fecha==20780

eststo m_41: mean trustusgov if fecha==20781
eststo m_42: mean trustusgov if fecha==20782
eststo m_43: mean trustusgov if fecha==20783
eststo m_44: mean trustusgov if fecha==20784
eststo m_45: mean trustusgov if fecha==20785
eststo m_46: mean trustusgov if fecha==20786
eststo m_47: mean trustusgov if fecha==20787
eststo m_48: mean trustusgov if fecha==20788
eststo m_49: mean trustusgov if fecha==20789
eststo m_50: mean trustusgov if fecha==20790

eststo m_51: mean trustusgov if fecha==20791

coefplot (m_1, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_2, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_3, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_4, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_5, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_6, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_7, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_8, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_9, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_10, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_11, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_12, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_13, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_14, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_15, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_16, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_17, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_18, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_19, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_20, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_21, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_22, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_23, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_24, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_25, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_26, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_27, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_28, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_29, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_30, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_31, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_32, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_33, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_34, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_35, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_36, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_37, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_38, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_39, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_40, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_41, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_42, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_43, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_44, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_45, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_46, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_47, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_48, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_49, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_50, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_51, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
	,vertical aspect(.5) nokey xtitle("Date") ytitle("Mean Trust in the US Gov't") title("") nolabel 

	
graph save meantrustovertime.gph, replace 
graph export meantrustovertime.png, replace


*Figure B.5. Proportion Trusting US Government by Date (Binary DV) 

eststo clear

eststo m_1: mean dummytrustusg if fecha==20741
eststo m_2: mean dummytrustusg if fecha==20742
eststo m_3: mean dummytrustusg if fecha==20743
eststo m_4: mean dummytrustusg if fecha==20744
eststo m_5: mean dummytrustusg if fecha==20745
eststo m_6: mean dummytrustusg if fecha==20746
eststo m_7: mean dummytrustusg if fecha==20747
eststo m_8: mean dummytrustusg if fecha==20748
eststo m_9: mean dummytrustusg if fecha==20749
eststo m_10: mean dummytrustusg if fecha==20750
eststo m_11: mean dummytrustusg if fecha==20751
eststo m_12: mean dummytrustusg if fecha==20752
eststo m_13: mean dummytrustusg if fecha==20753
eststo m_14: mean dummytrustusg if fecha==20754
eststo m_15: mean dummytrustusg if fecha==20755
eststo m_16: mean dummytrustusg if fecha==20756
eststo m_17: mean dummytrustusg if fecha==20757
eststo m_18: mean dummytrustusg if fecha==20758
eststo m_19: mean dummytrustusg if fecha==20759
eststo m_20: mean dummytrustusg if fecha==20760
eststo m_21: mean dummytrustusg if fecha==20761
eststo m_22: mean dummytrustusg if fecha==20762
eststo m_23: mean dummytrustusg if fecha==20763
eststo m_24: mean dummytrustusg if fecha==20764
eststo m_25: mean dummytrustusg if fecha==20765
eststo m_26: mean dummytrustusg if fecha==20766
eststo m_27: mean dummytrustusg if fecha==20767
eststo m_28: mean dummytrustusg if fecha==20768
eststo m_29: mean dummytrustusg if fecha==20769
eststo m_30: mean dummytrustusg if fecha==20770
eststo m_31: mean dummytrustusg if fecha==20771
eststo m_32: mean dummytrustusg if fecha==20772
eststo m_33: mean dummytrustusg if fecha==20773
eststo m_34: mean dummytrustusg if fecha==20774
eststo m_35: mean dummytrustusg if fecha==20775
eststo m_36: mean dummytrustusg if fecha==20776
eststo m_37: mean dummytrustusg if fecha==20777
eststo m_38: mean dummytrustusg if fecha==20778
eststo m_39: mean dummytrustusg if fecha==20779
eststo m_40: mean dummytrustusg if fecha==20780
eststo m_41: mean dummytrustusg if fecha==20781
eststo m_42: mean dummytrustusg if fecha==20782
eststo m_43: mean dummytrustusg if fecha==20783
eststo m_44: mean dummytrustusg if fecha==20784
eststo m_45: mean dummytrustusg if fecha==20785
eststo m_46: mean dummytrustusg if fecha==20786
eststo m_47: mean dummytrustusg if fecha==20787
eststo m_48: mean dummytrustusg if fecha==20788
eststo m_49: mean dummytrustusg if fecha==20789
eststo m_50: mean dummytrustusg if fecha==20790
eststo m_51: mean dummytrustusg if fecha==20791

coefplot (m_1, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_2, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_3, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_4, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_5, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_6, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_7, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_8, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_9, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_10, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_11, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_12, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_13, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_14, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_15, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_16, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_17, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_18, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_19, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_20, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_21, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_22, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_23, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_24, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_25, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_26, mcolor(black) msymbol(0) ciopts(lcolor(black))) ///
(m_27, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_28, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_29, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_30, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_31, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_32, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_33, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_34, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_35, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_36, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_37, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_38, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_39, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_40, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_41, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_42, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_43, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_44, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_45, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_46, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_47, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_48, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_49, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_50, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
(m_51, mcolor(maroon) msymbol(S) ciopts(lcolor(maroon))) ///
	,vertical aspect(.5) nokey xtitle("Date") ytitle("Proportion Trusting US Gov't") title("") nolabel 
	
graph save meantrustovertime_binary.gph, replace 
graph export meantrustovertime_binary.png, replace
 

*Figure B.6 Main Results with Binary DV

eststo clear
//Panel A: Full Sample with Country FE and City Size FE
eststo m_1: reg dummytrustusg i.posttrump i.country i.citysize
eststo m_2: reg dummytrustusg i.posttrump##c.time_zero i.country i.citysize
local n1 = `e(N)'

//Panel B: 7 day bandwidth with Country FE and City Size FE
eststo m_3: reg dummytrustusg i.posttrump_7days i.country i.citysize
eststo m_4: reg dummytrustusg i.posttrump_7days##c.time_zero i.country i.citysize 
local n3 = `e(N)'

//Panel C: 7 day bandwidth with Country FE and City Size FE plus covariate adjustment
eststo m_5: reg dummytrustusg i.posttrump_7days i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered remesas 
eststo m_6: reg dummytrustusg i.posttrump_7days##c.time_zero i.country i.citysize male age householdincome education working  voted_lastpresidential voteregistered remesas 
local n5 = `e(N)'

//Panel D: 7 day bandwidth with Country FE, City Size FE, and entropy balancing weights
eststo m_7: svy: reg dummytrustusg i.posttrump_7days i.country i.citysize
eststo m_8: svy: reg dummytrustusg i.posttrump_7days##c.time_zero i.country i.citysize  
local n7 = `e(N)'

//Generate variable capturing the sample included in the main analyses
gen sample_reg = e(sample)

//Generate Figure B.6

coefplot	(m_1, msize(medsmall)) (m_2, msize(medsmall) mcolor(gs9) ciopts(lcolor(gs9 gs9))) || ///
			(m_3, msize(medsmall)) (m_4, msize(medsmall)) || ///
			(m_5, msize(medsmall))  (m_6, msize(medsmall)) || ///
			(m_7, msize(medsmall)) (m_8, msize(medsmall)), ///
			drop(*.country *.citysize male age householdincome  education working  voted_lastpresidential voteregistered remesas _cons) xline(0, lpattern(solid)) byopts(row(2)) levels(95 90)	///
			bylabels("A. Full sample, N=`n1' " "B. ± 7 days, N=`n3' " "C. ± 7 days & Covariates, N=`n5' " "D. ± 7 days & Balancing, N=`n7' ") subtitle(, size(small)) nokey	///
			rename(1.posttrump = 1.posttrump_7days ///
			1.posttrump_14days = 1.posttrump_7days ///
			1.posttrump_21days = 1.posttrump_7days ///
			1.posttrump#c.time_zero = 1.posttrump_7days#c.time_zero ///
			1.posttrump_14days#c.time_zero = 1.posttrump_7days#c.time_zero ///
			1.posttrump_21days#c.time_zero = 1.posttrump_7days#c.time_zero) ///
			coeflabel(1.posttrump_7days = "Treatment"	///
			1.posttrump_7days#c.time_zero = "Treatment*Days" _cons = "Constant") ///
			aspect(.4) mlabgap(*2)   

addplot 1: , b1title("", size(small)) norescaling
addplot 2: , b1title("") norescaling
addplot 3: , b1title("Effect on Trust in US Gov't") norescaling
addplot 4: , b1title("Effect on Trust in US Gov't") norescaling

//Save Figure B.6

graph save Figure_1_binary.gph, replace 
graph export Figure_1_binary.png, replace 

drop sample_reg 


* Figure B.7 Placebo Test (Faux Election) with Binary DV

eststo clear

//Fictional Election Placebo Test, Naive

eststo m_1: reg dummytrustusg i.placebo_7days
eststo m_2: reg dummytrustusg i.placebo_7days##c.placebo_time_zero

//Fictional Election Placebo Test, Fixed Effects Only

eststo m_3: reg dummytrustusg i.placebo_7days i.country i.citysize
eststo m_4: reg dummytrustusg i.placebo_7days##c.placebo_time_zero i.country i.citysize

//Fictional Election Placebo Test, Fixed Effects Plus Covariate Adjustment

eststo m_5: reg dummytrustusg i.placebo_7days i.country i.citysize male age education working voted_last household voteregistered remesas
eststo m_6: reg dummytrustusg i.placebo_7days##c.placebo_time_zero i.country i.citysize male age education working voted_last household voteregistered remesas

//Generate variable capturing the sample included in the main analyses
gen sample_reg = e(sample)

//Generate Figure B.7

coefplot	(m_1, msize(medsmall)) (m_2, msize(medsmall) mcolor(gs9) ciopts(lcolor(gs9 gs9))) || ///
			(m_3, msize(medsmall)) (m_4, msize(medsmall)) || ///
			(m_5, msize(medsmall))  (m_6, msize(medsmall)) ,  ///
			drop(*.country *.citysize male age householdincome citysize education working  voted_lastpresidential voteregistered remesas _cons) xline(0, lpattern(solid)) byopts(row(1)) levels(95 90)	///
			bylabels("± 7 days, Naive" "± 7 days, FE" "± 7 days, FE + Cov.") subtitle(, size(small)) nokey	///
			coeflabel(1.placebo_7days = "Placebo Election"	///
			1.placebo_7days#c.placebo_time_zero = "Placebo Election*Days" _cons = "Constant") ///
			aspect(.4) mlabgap(*2) 

addplot 1: , b1title("Effect on Trust in US Gov't", size(small)) norescaling
addplot 2: , b1title("Effect on Trust in US Gov't") norescaling
addplot 3: , b1title("Effect on Trust in US Gov't") norescaling

//Save Figure B.7
graph save Figure_placebo2BINARY.gph, replace 
graph export Figure_placeboBINARY2.png, replace 

drop sample_reg


*Figure B.8 Placebo Test (Foreign Govs & Orgs) with Binary DV 

eststo clear

//Trust in China (Binary DV)
eststo m_1: reg dummytrustchina i.posttrump_7days i.country i.citysize male age education working voted_last household voteregistered remesas
eststo m_2: reg dummytrustchina i.posttrump_7days##c.time_zero i.country i.citysize

//Trust in United Nations (Binary DV)
eststo m_3: reg dummytrustun i.posttrump_7days i.country i.citysize male age education working voted_last household voteregistered remesas
eststo m_4: reg dummytrustun i.posttrump_7days##c.time_zero i.country i.citysize male age education working voted_last household voteregistered remesas

//Trust in Organization of American States (Binary DV)
eststo m_5: reg dummytrustoas i.posttrump_7days i.country i.citysize male age education working voted_last household voteregistered remesas
eststo m_6: reg dummytrustoas i.posttrump_7days##c.time_zero i.country i.citysize male age education working voted_last household voteregistered remesas

//Generate variable capturing the sample included in the main analyses
gen sample_reg = e(sample)

//Generate Figure B.8

coefplot	(m_1, msize(medsmall)) (m_2, msize(medsmall) mcolor(gs9) ciopts(lcolor(gs9 gs9))) || ///
			(m_3, msize(medsmall)) (m_4, msize(medsmall)) || ///
			(m_5, msize(medsmall))  (m_6, msize(medsmall)) ,  ///
			drop(*.country *.citysize male age householdincome citysize education working  voted_lastpresidential voteregistered remesas _cons) xline(0, lpattern(solid)) byopts(row(1)) levels(95 90)	///
			bylabels("A. Trust China, ± 7 days" "B. Trust UN, ± 7 days" "C. Trust OAS, ± 7 days") subtitle(, size(small)) nokey	///
			coeflabel(1.posttrump_7days = "Treatment group"	///
			1.posttrump_7days#c.time_zero = "Treatment*Days" _cons = "Constant") ///
			aspect(.6) mlabgap(*2)
			
addplot 1: , b1title("Effect on Trust", size(small)) norescaling
addplot 2: , b1title("Effect on Trust") norescaling
addplot 3: , b1title("Effect on Trust") norescaling

graph save Figure_placebogovsBINARY.gph, replace 
graph export Figure_placebogovsBINARY.png, replace

drop sample_reg

**The End**

**Questions? Feel free to contact the authors at rbateson@uottawa.ca and ml.weintraub@uniandes.edu.co
